package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.PixelSnapping;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	public final class ParabolaDrower extends PlayBase
	{
		public function ParabolaDrower(){super();}
		
		private var bmpData:BitmapData;
		private const bitmap:Bitmap = new Bitmap(bmpData,PixelSnapping.NEVER, true);
		override protected function addedToStage():void
		{
			addChild(bitmap);
		} 
		
		override protected function resized(width:uint, height:uint):void
		{
			bmpData = new BitmapData(width, height, false, 0);
			bitmap.bitmapData = bmpData;
		}
		private const timer:Timer = new Timer(100,1);
		private var color:uint = 0xFF0000;
		override protected function enterFrame():void
		{
			if (timer.running)
				return;
			timer.start();
			bmpData.lock();
			const multiplayer:Number = .05 - random * .1;
			const xOffset:int = random * 1000;
			const yOffset:int = random * 1000;
			const direction:Boolean = random > .5;
			var x:int;
			var y:int;
			trace('		x:',xOffset,'		y:',yOffset,'		m:',multiplayer);
			for (var i:uint; i++ < 2000;)
			{
				x = i - xOffset;
//				if (x > stageWidth)
//					continue;
				y = multiplayer * x * x + yOffset;
//				if (0 < y && y < stageHeight)
					direction ? bmpData.setPixel(i, y, color) :
						bmpData.setPixel(y, i, color);
			}
			
			if (i++ > stageWidth)
			{
				i = 0;
				if (color & 1 > 0)
					color |= 0x1000000; 
				color >>= 1;
			}
			doBlur();
			bmpData.unlock();
		}
		private function zoom():void
		{
			const colorTransform:ColorTransform = new ColorTransform();
			const matrix:Matrix = new Matrix();
//			colorTransform.alphaMultiplier = .9;
			//m.translate(-bmpd.width*.05,-bmpd.height*.05);
			
//			matrix.translate(- random, - random);
//			matrix.scale(1.0001, 1.0001);
			//				matrix.rotate(.0001);
			bmpData.draw(bmpData, matrix, colorTransform);
		}
		
		private const point:Point = new Point();
		private const blurFilter:BlurFilter = new BlurFilter(1.04, 1.04);
		private function doBlur():void	{bmpData.applyFilter(bmpData,bmpData.rect, point, blurFilter);}
	}
}